            <div>
				<ul class="breadcrumb">
					<li>
						<a href="<?php echo site_url("menu/survey"); ?>">Quản lý khảo sát</a> / 
						<a href="<?php echo site_url("surveytype"); ?>">Loại khảo sát</a> / 
						<a href="<?php echo site_url("survey/index/" . $st->survey_type_id); ?>"><?php echo $st->survey_type_name ?></a> / 
						<a href="<?php echo site_url("survey/details/" . $survey->survey_id); ?>"><?php echo $survey->survey_name ?></a> / 
						Sửa câu hỏi
					</li>
				</ul>
			</div>
			<div class="row-fluid">
				<div class="box span12">
					<div class="box-header well">
						<h2><i class="icon-pencil"></i> Chỉnh sửa câu hỏi</h2>
						<div class="box-icon">
							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						</div>
					</div>
					<div class="box-content">
						<form class="form-horizontal" method="post">
							<fieldset>
								<div class="control-group">
									<label class="control-label" for="content">Câu hỏi</label>
									<div class="controls">
                                        <input name="qid" type="hidden" />
										<input class="input-file uniform_on span8" id="content" name="content" type="text" value="<?php echo $q->content;?>"/>
                                        <?php echo form_error('content'); ?>
									</div>
								</div>
								<div class="control-group"> 
									<label class="control-label"></label>
									<div>
										<label class="checkbox inline">
											<input type="checkbox" id="required" name="required" value="true" <?php if($q->required == true) echo 'checked'?>/>Câu hỏi cần phải trả lời. 
										</label>									
									</div>
								</div>
								<div class="control-group"> 
									<label class="control-label"></label>
									<div>
										<label class="checkbox inline">
											<input type="checkbox" id="shide" name="shide" value="true" <?php if($q->start_hide == true) echo 'checked'?>/>Câu hỏi ẩn.
										</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label" for="vorder">Thứ tự sắp xếp</label>
									<div class="controls">
										<select id="vorder" name="vorder" data-rel="chosen">
                                            <option></option>
                                            <?php for($i=1; $i<=$maxq; $i++){ ?>
											     <option <?php if($q->view_order == $i) echo 'selected="true"'?> value="<?php echo $i ?>"><?php echo $i ?></option>
                                            <?php };?>
										</select>
                                        <?php echo form_error('vorder'); ?>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label" for="otype">Câu trả lời dạng</label>
									<div class="controls">
										<select id="otype" name="otype" data-rel="chosen">
											<option <?php if($otype == 'r ') echo 'selected="true"'?> value="r">Chỉ chọn một</option>
											<option <?php if($otype == 'c ') echo 'selected="true"'?> value="c">Nhiều lựa chọn</option>
                                            <option <?php if($otype == 't ') echo 'selected="true"'?> value="t">Text</option>
										</select>
										<?php echo form_error('otype'); ?>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label" for="vstyle">Thể hiện</label>
									<div class="controls">
										<select id="vstyle" name="vstyle" data-rel="chosen">
											<option <?php if($q->view_style == 1) echo 'selected="true"'?> value="1">1 cột</option>
											<option <?php if($q->view_style == 2) echo 'selected="true"'?> value="2">2 cột</option>
										</select>
                                        <?php echo form_error('vstyle'); ?>
									</div>
								</div>
                                <div id="answer-group">
                                    <div id="normal-answer-group">
										<?php foreach($atlist as $at){?>
											<?php if($at->option_type == 'pr'){?>
												<div index="<?php echo $at->view_order; ?>" type="pr" class="control-group">
													<div class="controls">
														<div class="input-append">
															<input type="hidden" name="otypes[]" value="pr"/>
															<input name="labels[]" type="text" value="<?php echo $at->label;?>"/><button index="<?php echo $at->view_order;?>" class="btn btn-danger btn-delete-answer" type="button">Xoá</button>
															<select>
															<?php foreach($prlist as $pr){ ?>
																<option><?php echo $pr->province_name;?></option>
															<?php };?>
															</select>
														</div>
													</div>
												</div>
											<?php }else if($at->option_type != 'rt' && $at->option_type != 'ct'){?>
												<div index="<?php echo $at->view_order; ?>" class="control-group">
													<div class="controls">
														<div class="input-append">
															<?php if($at->option_type == 'r '){ ?>
																<input disabled="true" type="radio"/>
																<input type="hidden" name="otypes[]" value="r"/>
																<input name="labels[]" type="text" value="<?php echo $at->label;?>"/><button index="<?php echo $at->view_order;?>" class="btn btn-danger btn-delete-answer" type="button">Xoá</button>
															<?php }else if($at->option_type == 'c '){ ?>
																<input disabled="true" type="checkbox"/>
																<input type="hidden" name="otypes[]" value="c"/>
																<input name="labels[]" type="text" value="<?php echo $at->label;?>"/><button index="<?php echo $at->view_order;?>" class="btn btn-danger btn-delete-answer" type="button">Xoá</button>
															<?php }else if($at->option_type == 't '){ ?>
																<input type="hidden" name="otypes[]" value="t"/>
																<input name="labels[]" type="text" value="<?php echo $at->label;?>"/><button index="<?php echo $at->view_order;?>" class="btn btn-danger btn-delete-answer" type="button">Xoá</button>
															<?php } ?>
														</div>
													</div>
												</div>
											<?php };?>
										<?php };?>
									</div>
                                    <div id="other-answer-group">
										<?php if($atlist[$q->max_option-1]->option_type == 'rt'){?>
											<div index="<?php echo $q->max_option;?>" class="control-group">
												<label class="control-label">Lựa chọn khác</label>
												<div class="controls">
													<div class="input-append">
														<input disabled="true" type="radio"/>
														<input type="hidden" name="otypes[]" value="rt"/>
														<input name="labels[]" type="text" value="<?php echo $atlist[$q->max_option-1]->label;?>"/><button index="<?php echo $q->max_option;?>" class="btn btn-danger btn-delete-answer" type="button">Xoá</button>
													</div>
												</div>
											</div>
										<?php }else if($atlist[$q->max_option-1]->option_type == 'ct'){?>
											<div index="<?php echo $q->max_option;?>" class="control-group">
												<label class="control-label">Lựa chọn khác</label>
												<div class="controls">
													<div class="input-append">
														<input disabled="true" type="checkbox"/>
														<input type="hidden" name="otypes[]" value="ct"/>
														<input name="labels[]" type="text" value="<?php echo $atlist[$q->max_option-1]->label;?>"/><button index="<?php echo $q->max_option;?>" class="btn btn-danger btn-delete-answer" type="button">Xoá</button>
													</div>
												</div>
											</div>
										<?php };?>
									</div>
									<?php echo $check_number_of_answer_templates;?>
                                </div>
								<div class="control-group">
									<div class="controls">
                                        <div class="btn-group">
                							<a href="#" class="btn btn-setting" id="addanswer">Thêm câu trả lời</a>
                							<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
                							<ul class="dropdown-menu">
                								<li><a href="#" id="addotheranswer">Thêm lựa chọn khác</a></li>
                								<li><a href="#" id="addprovinceanswer" style="display: none;">Thêm lựa chọn tỉnh/thành phố</a></li>
                							</ul>
                						</div>
									</div>
								</div>
								<div class="form-actions">
									<button type="submit" class="btn btn-primary" name="submit" value="submit"> Lưu</button>
									<a class="btn" href="<?php echo site_url("survey/edit_step3");?>">Hủy</a>
								</div>
							</fieldset>
						</form>
					</div>
				</div><!--/span-->
            </div>
        <!-- Hidden dialog -->
    <!-- Placed at the end of the document so the pages load faster -->
    <!-- Internal Script -->
    <script type="text/javascript">
        $(document).ready(function(){
            var otype = $('#otype option:selected').val();
            if(otype=='r' || otype=='c'){
                $('#addotheranswer').show();
                $('#addprovinceanswer').hide();
            }else if(otype=='t'){					
                $('#addotheranswer').hide();
                $('#addprovinceanswer').show();
            }
			
			//index of added answer
            var index = <?php echo $maxq + 1;?>;
            
            //Event of add answer button
            $('#addanswer').click(function(){
				//Get current option type
                var otype = $('#otype').val();
                $.get('<?php echo base_url();?>survey/add_answer_template/' + otype + '/' + index, function(data, result){
                    if(result=='success')
                        $('#normal-answer-group').append(data);
                });
				index++;
            });
            //Event of add other answer button
            $('#addotheranswer').click(function(){
                var otype = $('#otype').val() + 't';
				$.get('<?php echo base_url();?>survey/add_answer_template/' + otype + '/' + index, function(data, result){
                    if(result=='success')
                        $('#other-answer-group').html(data);
                });
				index++;
            });
			//Event of add province answer button
			$('#addprovinceanswer').click(function(){
				var otype = 'pr';
                $.get('<?php echo base_url();?>survey/add_answer_template/' + otype + '/' + index, function(data, result){
                    if(result=='success')
                        $('#normal-answer-group').append(data);
                });
				index++;
			});
            //Event of delete answer template
            $('.btn-delete-answer').click(function(){
                var i = $(this).attr('index');
                $('div[index=' + i + ']').remove();
            });
            //Event of combobox option type
            $('#otype').change(function(){
                var otype = $('#otype option:selected').val();
                
                $(".input-append [type='radio']").remove();
                $(".input-append [type='checkbox']").remove();
				$(".input-append .radio").remove();
                $(".input-append .checker").remove();
                if(otype=='r'){
					//remove province answer
					$("div[type='pr']").remove();
                    $("#answer-group .input-append").prepend("<input disabled='true' type='radio'>");
					//change option type of answer template
					$("#answer-group input[value='c']").val('r');
					$("#answer-group input[value='ct']").val('rt');
					$("#answer-group input[value='t']").val('r');
					
                    $('#addotheranswer').show();
                    $('#addprovinceanswer').hide();
                }else if(otype=='c'){
					//remove province answer
					$("div[type='pr']").remove();
                    $("#answer-group .input-append").prepend("<input disabled='true' type='checkbox'>");
					//change option type of answer template
					$("#answer-group input[value='r']").val('c');
					$("#answer-group input[value='rt']").val('ct');
					$("#answer-group input[value='t']").val('c');
					
                    $('#addotheranswer').show();
                    $('#addprovinceanswer').hide();
                }else if(otype=='t'){
					//remove 'other' answer
                    $('#other-answer-group').html('');
					//change option type of answer template
					$("#answer-group input[value='r']").val('t');
					$("#answer-group input[value='c']").val('t');
					
                    $('#addotheranswer').hide();
                    $('#addprovinceanswer').show();
                }
            });
        });
    </script>
    <!-- End Internal Script -->